home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / mced-1.1.lha / CEDScripts / Indent.ced next >
Encoding:
Text File  |  1992-09-02  |  2.1 KB  |  74 lines

  1. /*
  2. **    Indent.ced
  3. **    
  4. **    $VER: Indent.ced 1.0 (18.2.95)
  5. **    
  6. **    This script can indent a line or block. It adds a tabulation char at the
  7. **    beginning of current line or each line in block if block is marked.
  8. **    Useful for editing source.
  9. **    
  10. **    This script requires CygnusEd Professional v3.5 (or later) to run.
  11. **    
  12. **    Copyright © 1995 Michael Letowski
  13. */
  14.  
  15. /* Get host */
  16. PARSE SOURCE Com Res Called Resolved Ext Host .
  17. IF Host="REXX" THEN                                                /* From command line */
  18.     ADDRESS "rexx_ced"                                            /* Talk to default CEd */
  19.  
  20. OPTIONS RESULTS                                                        /* Hear it from CEd */
  21.  
  22. GV.TAB="09"X
  23. GV.LF="0A"X
  24. GV.Ops=0                                                                    /* Number of operations for Undo.ced */
  25.  
  26. 'Status CURSORMEMORYX'                                        /* Get position of cursor in line */
  27. Pos=RESULT
  28.  
  29. 'DM "Indenting..."'
  30.  
  31. 'Cut block'                                                                /* Cut marked block */
  32. Block=RESULT
  33. IF Block THEN                                                            /* There is a marked block */
  34.     CALL IndentBlock                                                /* Indent block */
  35. ELSE                                                                            /* No marked block */
  36.     CALL IndentLine                                                    /* Indent line */
  37.  
  38. CALL SetClip(UndoClipName(),GV.Ops)                /* Set data for Undo.ced */
  39.  
  40. 'Status LINEBUFFEROFFSET'                                    /* Get position of line */
  41. Pos=Pos+RESULT
  42.  
  43. 'Jump to byte' Pos+~Block                                    /* Move cursor to old position */
  44. 'DM'                                                                            /* Restore status line */
  45.  
  46. EXIT                                                                            /* Finished */
  47.  
  48. IndentBlock:    PROCEDURE EXPOSE GV.
  49.     'Status BLOCKBUFFER'                                        /* Get buffer */
  50.     ToIndent=RESULT                                                    /* And store it */
  51.     IF Length(ToIndent)=0 THEN DO                        /* Nothing to indent */
  52.         'Okay1' "No area marked."
  53.         RETURN
  54.     END
  55.     GV.Ops=GV.Ops+1
  56.     InsPos=0
  57.     DO UNTIL InsPos=0                                                /* For each line... */
  58.         ToIndent=Insert(GV.Tab,ToIndent,InsPos)
  59.         InsPos=Pos(GV.LF,ToIndent,InsPos+1)        /* Find end of a line */
  60.     END
  61.     'Text' ToIndent                                                    /* Insert back to CED */
  62.     GV.Ops=GV.Ops+RESULT
  63. RETURN
  64.  
  65. IndentLine:    PROCEDURE EXPOSE GV.
  66.     'Beg of line'                                                        /* Jump to beginning of line */
  67.     'Text' GV.TAB                                                        /* Insert tab */
  68.     GV.Ops=GV.Ops+RESULT                                        /* Increase number of ops */
  69. RETURN
  70.  
  71. UndoClipName:
  72.     'Status FILEMEM'                                                /* Get address of current file */
  73. RETURN "CEDUndo."Right(D2X(RESULT),8,"0")    /* Prepare unique name */
  74.